package Demo01_15;

/**
 * Created by 14229 on 2020/1/16.
 */
public class Test12 {
    public static void main(String[] args) {
      //准备数据            语  数  外
        String[][] all = {
                {"张三","37","89","5"},
                {"李四","95","41","79"},
                {"王五","60","84","29"},
                {"赵六","87","46","86"}
        };
        printMathScore(all);

        int sum = getCountMathScore(all);
        System.out.println("所有同学的数学成绩总和为："+sum);

        int i = getAvgMathScore(all);
        System.out.println("所有同学的数学成绩平均分为："+i);

        getAvgName(all);

        int avgCount = getAvgCount(all);
        System.out.println("数学成绩高过平均分的人数为："+avgCount);

        fujia(all);
    }
    public static void printMathScore(String[][] all){
        System.out.println("所有同学的数学成绩为：");
        for (int i = 0; i <all.length ; i++) {
            System.out.println(all[i][0]+all[i][2]);
        }
    }
    public static int getCountMathScore(String[][] all){
        int sum = 0;
        for (int i = 0; i <all.length ; i++) {
            sum+=Integer.parseInt(all[i][2]);
        }
        return sum;
    }
    public static int getAvgMathScore(String[][] all){
        int i = getCountMathScore(all);
        int i1 = i / all.length;
        return i1;
    }
    public static void getAvgName(String[][] all){
        int i = getAvgMathScore(all);
        System.out.print("数学成绩超过平均分是人是：");
        for (int j = 0; j <all.length ; j++) {
            if (i<Integer.parseInt(all[j][2])){
                System.out.print(all[j][0]+" ");
            }
        }
    }
    public static int getAvgCount(String[][] all){
        int i = getAvgMathScore(all);
        int count = 0;
        for (int j = 0; j <all.length ; j++) {
            if (i<Integer.parseInt(all[j][2])){
                count++;
            }
        }
        return count;
    }
    public static void fujia(String[][] all){
        // 找到平均成绩最高的学科------------------------------------------
        double sumy = 0;
        double sums = 0;
        double sumw = 0;
        for (int i = 0; i <all.length ; i++) {
            sumy+=Integer.parseInt( all[i][1]);
            sums+=Integer.parseInt( all[i][2]);
            sumw+=Integer.parseInt( all[i][3]);
        }
        sumy = sumy/all.length;
        sums = sums/all.length;
        sumw = sumw/all.length;
        double d = sumy > sums ? sumy :sums;
        double v = d > sumw ? d : sumw;
        int s = 0;
        if (v==sumy){
            s = 1;
            System.out.println("平均成绩最高学科为：语文");
        }else if (v==sums){
            s = 2;
            System.out.println("平均成绩最高学科为：数学");
        }else if (v==sumw){
            s = 3;
            System.out.println("平均成绩最高学科为：外语");
        }
        // ---------------------------------------------------------------------
        //  获取该学科前三名同学的姓名------------------------------------------
        int min = Integer.parseInt(all[0][s]);
        for (int i = 0; i <all.length; i++) {
            if (min>Integer.parseInt(all[i][s])){
                min = Integer.parseInt(all[i][s]);
            }
        }
        System.out.println("该学科前三名同学的姓名为：");
        for (int i = 0; i <all.length ; i++) {
            if (min != Integer.parseInt(all[i][s])){
                System.out.println(all[i][0]);
            }
        }
        //--------------------------------------------------------------------------
        //请找出不及格的科数小于等于1门的同学，且总成绩大于180分---------------------

        System.out.print("不及格的科数小于等于1门，且总成绩大于180分的同学是：");
        for (int i = 0; i <all.length ; i++) {
            int sum = 0;
            int count = 0;
            for (int j = 1; j <all.length ; j++) {
                sum+=Integer.parseInt(all[i][j]);
                if (Integer.parseInt(all[i][j])<60){
                    count++;
                }
            }
            if (count<=1&&sum>180){
                System.out.print(all[i][0]+" ");
            }
        }
    }
}
